package com.platform.module.admin.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.platform.module.admin.define.Deserializer;
import com.platform.module.admin.define.Serializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

@Configuration
public class JacksonConfig {
    @Bean
    public ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(getModule());
        return objectMapper;
    }

    private static Module getModule() {
        SimpleModule module = new SimpleModule();
        module.addSerializer(LocalDateTime.class, new Serializer.LocalDateTimeSerializer());
        module.addDeserializer(LocalDateTime.class, new Deserializer.LocalDateTimeDeserializer());
        return module;
    }
}
